<div class="content">
   	<div class="list_button">
        <table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
        <tr>
            <td>
                <?php
				
					echo CHtml::link(
						"<div class='button'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-plus.png") .
							"</div>" .
							"<div style='float:left; width:80px;'>".
								"Thêm mới" .
							"</div>" .
						"</div>"
						,
                       array($this->controller_id."/add","page"=> $page)
                    );
					
					echo "<div class='button' id='delete_multi'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-remove.png") .
							"</div>" .
							"<div style='float:left; width:40px;'>".
								"Xóa" .
							"</div>" .
						"</div>";
					
                    echo "<div style='color:#f00; font-size:12px; padding-top:7px;'>";
						echo "<strong>* Chú ý:</strong> Chỉ xóa các User Offline.";
					echo "</div>" ;
                ?>
                <script language="javascript">
                $(document).ready(function(){
                    $('#delete_multi').click(function(){
                        var form = document.getElementById("form_table_all");
                        form.submit();
                    });	
                })
              </script>
            </td>
            
            <td align="right">
             </td>
          </tr>
        </table>
	</div>

    <table class="view">
        <tr height='25'>
            <th width="50px"> # </th>
            <th width="30">
                <?php 
                    echo CHtml::checkBox("checkbox_all", false, array("id"=>"checkbox_all"));
                ?>
            </th>
            <th colspan="2">Action</th>
            <th>Username</th>
            <th width="80">Bật / Tắt</th>
            <th width="80">Password</th>
            <th width="60">Online</th>
            <th width="100">Ngày tạo</th>
            <th width="140">Đăng nhập cuối</th>
            <th width="80">IP</th>
            <th width="50">ID</th>
        </tr>
        <?php
            if (! is_null($rows))
            {
                echo CHtml::beginForm(
					array($this->controller_id."/delete_multi", 
						"page" => $page
					),
					"post",
                    array("id"=>"form_table_all")
				);
                
                $i = 1;
                foreach($rows as $user)
                {
                    echo "<tr>";
					
                        echo "<td align='center'>";
                            echo $i++;
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            echo CHtml::checkBox("cib[".$user["id"]."]", false, array("id"=>"cb".$i));
                        echo "</td>";
                        
                        echo "<td width='26px' align='center'>";
						
							$url = Yii::app()->createUrl(
								$this->route."/delete",
								array(
									"user_id" => $user["id"],
									"page" => $page
								)
							);
							
							echo CHtml::image(
								Yii::app()->baseUrl.'/assets/icon/icon-16-trash.png',
								"",
								array(
									"style"=>"cursor:pointer",
									"title"=>"Delete",  
									"onClick"=>"javascript:actionDelete('".$url."');"
								)
							);
							
                        echo "</td>";
                        
                        echo "<td width='26px' align='center'>";
                            echo CHtml::link(
                                CHtml::image(Yii::app()->baseUrl.'/assets/icon/icon-16-edit.png'),
                                array(
                                    $this->controller_id."/edit",
                                    "user_id" => $user["id"],
									"page" => $page
                                ),
                                array('title'=>'edit')
                            );
                        echo "</td>";
                            
                        echo "<td>";
                            echo CHtml::link(	
                                $user["username"],
                                array(
                                    $this->controller_id."/edit",
                                    'user_id' => $user["id"],
									"page" => $page
                                ),
                                array('title'=>'Edit')
                            );
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            $icons =  array(
                                0 => "icon-16-remove.png",
                                1 => "icon-16-tick.png",
                            );
                            echo CHtml::link(
                                CHtml::image(
									Yii::app()->baseUrl.'/assets/icon/'.$icons[$user["enable"]]
								),
                                array($this->controller_id."/enable", 
                                    "user_id"=>$user["id"],
                                    "page" => $page
                                )
                            );
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            echo CHtml::link(
                                CHtml::image(Yii::app()->baseUrl.'/assets/icon/icon-16-license.png'),
                                array(
                                    strtolower("user/change_password"),
                                    'user_id' => $user["id"],
                                    "page" => $page
                                ),
                                array('title'=>"Đổi Password")
                            );
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            $session_userid_array = session::model()->findAll(
								array("select"=>"user_id")
							);
                            
                            $online = 0;
                            
                            foreach($session_userid_array as $session_userid)
                            {
                                if ($user["id"] == $session_userid->user_id)
                                {
                                    $online = 1;
                                    break;
                                }
                            }
                            
                            $icons = array(
                                0=>"icon-16-circle.png",
                                1=>"icon-16-online.png"	
                            );
                            
                            if ($online == 1)
                            {
                                echo CHtml::link(
                                    CHtml::image(Yii::app()->baseUrl."/assets/icon/".$icons[$online]),
                                    array(
                                        $this->controller_id."/kickout",
                                        'user_id' => $user["id"],
                                    ),
                                    array("title"=>"Kick out")
                                );
                                    
                            }
                            else
                                echo CHtml::image(Yii::app()->baseUrl."/assets/icon/".$icons[$online]);
                            
                            //print_r($who_online_array);
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            echo "<span style='color:red'>";
                            echo MyHelper::get_date_parse($user["create_time"]);
                            echo "</span>";
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            echo $user["last_visit"];
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            echo $user["last_ipaddress"];
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            echo $user["id"];
                        echo "</td>";
						
                    echo "</tr>";        
                }
                
                echo CHtml::endForm(); // end form
            }
        ?>
    </table>
</div><!-- end div content -->

<?php 
	// display pagination
	if ($pages->pageCount > 1)
	{
		echo "<div class='pagination'>";
			$this->widget('CLinkPager', array(
				'header' => "",
				'cssFile' => Yii::app()->baseUrl."/assets/css/pager.css",
				"prevPageLabel" => "«",
				"nextPageLabel" => "»",
				'pages' => $pages,
			));
			
			$this->widget('CListPager', array(
				//"promptText" => "Chuyển nhanh",
				"header" => "Trang ",
				'pages'=>$pages
			));
		echo "</div>";
	}
?>

<script language="javascript">
function actionDelete(url)
{	
	if (confirm("Bạn muốn xóa mẫu tin này ?") == true)
		window.location = url;
}
</script>